From 7486e5d07ed90b787e3389f75b862e8669a7b136 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 7 Feb 2003 07:24:23 +0000 Subject: [PATCH] Add new 'arglist' stuff so that file formats with options can be seen in the help message. --- gpsbabel/defs.h | 7 +++++++ gpsbabel/magproto.c | 15 +++++++++++---- gpsbabel/vecs.c | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 201257a4c..69f9ec7a1 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -202,6 +202,12 @@ void setshort_mustupper(void *, int n); void setshort_mustuniq(void *, int n); void setshort_whitespace_ok(void *, int n); +typedef struct arglist { + char *argstring; + char **argval; + char *helpstring; +} arglist_t; + typedef struct ff_vecs { ff_init rd_init; ff_init wr_init; @@ -209,6 +215,7 @@ typedef struct ff_vecs { ff_deinit wr_deinit; ff_read read; ff_write write; + arglist_t *args; } ff_vecs_t; void waypt_init(void); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index efe0f9bdf..4fae3957f 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -40,6 +40,9 @@ static double mag2degrees(double mag_val); static void mag_readmsg(void); static void *mkshort_handle; static char *deficon; +static char *bs; +static char *noack; + typedef enum { mrs_handoff = 0, @@ -661,14 +664,18 @@ termwrite(char *obuf, int size) } #endif +static +arglist_t mag_args[] = { + {"baud", &bs, "Numeric value of bitrate (baud=4800)"}, + {"noack", &noack, "Suppress use of handshaking in name of speed"}, + {"deficon", &deficon, "Default icon name"}, + {0, 0, 0} +}; static void mag_rd_init(const char *portname, const char *args) { time_t now, later; - char * bs = get_option(args, "baud"); - char * noack = get_option(args, "noack"); - deficon = get_option(args, "deficon"); if (bs) { bitrate=atoi(bs); @@ -721,7 +728,6 @@ mag_wr_init(const char *portname, const char *args) } #else struct stat sbuf; - deficon = get_option(args, "deficon"); magfile_out = fopen(portname, "w+b"); fstat(fileno(magfile_out), &sbuf); is_file = S_ISREG(sbuf.st_mode); @@ -1145,4 +1151,5 @@ ff_vecs_t mag_vecs = { mag_deinit, mag_read, mag_write, + mag_args }; diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index f7dfb6bd6..14a541f77 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -230,16 +230,30 @@ find_vec(char *const vecname, char **opts) char *svecname = strtok(v, ","); while (vec->vec) { - if (strcmp(svecname, vec->name) == 0) { - char * res = strchr(vecname, ','); - if (res) - *opts = strchr(vecname, ',')+1; - else - *opts = NULL; - free(v); - return vec->vec; + arglist_t *ap; + char *res; + + if (strcmp(svecname, vec->name)) { + vec++; + continue; + } + + res = strchr(vecname, ','); + if (res) { + *opts = strchr(vecname, ',')+1; + + if (vec->vec->args) { + for (ap = vec->vec->args; ap->argstring; ap++){ + *ap->argval = get_option(*opts, ap->argstring); + } + } + } else { + *opts = NULL; } - vec++; + + free(v); + return vec->vec; + } free(v); return NULL; @@ -295,9 +309,15 @@ void disp_vecs(void) { vecs_t *vec; + arglist_t *ap; + for (vec = vec_list; vec->vec; vec++) { printf(" %-20.20s %-50.50s\n", vec->name, vec->desc); + for (ap = vec->vec->args; ap && ap->argstring; ap++) { + printf(" %-10.10s %-40.40s\n", + ap->argstring, ap->helpstring); + } } } -- 2.30.2